Skip to content
c++
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5, LOG = 20;
int dep[N << 1], up[N << 1][LOG];
std::vector<int> g[N], adj[N << 1];
int dfn[N], low[N], timer;
int stk[N], top;
int n, m, tot;
void add(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}
void tarjan(int u) {
    dfn[u] = low[u] = ++timer;
    stk[++top] = u;
    for (int v : g[u]) {
        if (!dfn[v]) {
            tarjan(v);
            low[u] = std::min(low[u], low[v]);
            if (low[v] >= dfn[u]) {
                int sq = ++tot;
                add(sq, u);
                do {
                    add(sq, stk[top]);
                } while (stk[top--] != v);
            }
        } else {
            low[u] = std::min(low[u], dfn[v]);
        }
    }
}

void dfs(int u, int f) {
    dep[u] = dep[f] + 1;
    up[u][0] = f;
    for (int i = 1; i < LOG; i++) up[u][i] = up[up[u][i - 1]][i - 1];
    for (int v : adj[u])
        if (v != f) dfs(v, u);
}

int lca(int u, int v) {
    if (dep[u] < dep[v]) std::swap(u, v);
    int d = dep[u] - dep[v];
    for (int i = LOG - 1; i >= 0; i--)
        if ((d >> i) & 1) u = up[u][i];
    if (u == v) return u;
    for (int i = LOG - 1; i >= 0; i--)
        if (up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
    return up[u][0];
}

inline int dis(int u,int v){
    return dep[u]+dep[v]-2*dep[lca(u,v)];
}
bool is(int a,int b,int c){
    return dis(a,b) == dis(a,c)+dis(c,b);
}

bool solve1(int a, int b, int c, int d) {
    if (is(a, b, c) && is(a, b, d)) {
        int fc = up[c][0]; 
        int fd = up[d][0];
        if (fc == fd) return true;
        if (up[fc][0] == d) {
            return adj[fc].size() > 2;
        } else {
            return adj[fd].size() > 2;
        }
    } else {
        return true;
    }
    return false;
}

bool solve2(int a, int b, int c) {
    return !is(a, b, c);
}
void fc() {
    std::cin >> n >> m;
    tot = n;
    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    tarjan(1);
    dfs(1, 0);
    int q;
    std::cin >> q;
    while (q--) {
        int x;
        std::cin >> x;
        bool ok = false;
        if (x == 1) {
            int a, b, c, d;
            std::cin >> a >> b >> c >> d;
            ok = solve1(a, b, c, d);
        } else {
            int a, b, c;
            std::cin >> a >> b >> c;
            ok = solve2(a, b, c);
        }
        std::cout << (ok ? "yes" : "no") << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // std::cin>>t;
    while (t--) fc();
    return 0;
}